package com.turnengine.client.local.location.bean;

import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * The Coordinate Range.
 */
public class CoordinateRange implements ICoordinateRange, Comparable<ICoordinateRange> {

	/** The start location id. */
	private int startLocationId = -1;
	/** The finish location id. */
	private int finishLocationId = -1;

	/**
	 * Creates a new Coordinate Range.
	 */
	public CoordinateRange() {
	}

	/**
	 * Creates a new Coordinate Range.
	 * @param startLocationId the start location id
	 * @param finishLocationId the finish location id
	 */
	public CoordinateRange(int startLocationId, int finishLocationId) {
		setStartLocationId(startLocationId);
		setFinishLocationId(finishLocationId);
	}

	/**
	 * Creates a new Coordinate Range.
	 * @param coordinateRange the coordinate range
	 */
	public CoordinateRange(CoordinateRange coordinateRange) {
		setStartLocationId(coordinateRange.getStartLocationId());
		setFinishLocationId(coordinateRange.getFinishLocationId());
	}

	/**
	 * Creates a new Coordinate Range.
	 * @param iCoordinateRange the i coordinate range
	 */
	public CoordinateRange(ICoordinateRange iCoordinateRange) {
		setStartLocationId(iCoordinateRange.getStartLocationId());
		setFinishLocationId(iCoordinateRange.getFinishLocationId());
	}

	/**
	 * Returns the start location id.
	 * @return the start location id.
	 */
	public int getStartLocationId() {
		return startLocationId;
	}

	/**
	 * Returns the finish location id.
	 * @return the finish location id.
	 */
	public int getFinishLocationId() {
		return finishLocationId;
	}

	/**
	 * Sets the start location id.
	 * @param startLocationId the start location id to set.
	 */
	public void setStartLocationId(int startLocationId) {
		this.startLocationId = startLocationId;
	}

	/**
	 * Sets the finish location id.
	 * @param finishLocationId the finish location id to set.
	 */
	public void setFinishLocationId(int finishLocationId) {
		this.finishLocationId = finishLocationId;
	}

	/**
	 * Returns the hash code.
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		HashCodeBuilder hash = new HashCodeBuilder(683, 37);
		hash.append(startLocationId);
		hash.append(finishLocationId);
		return hash.toHashCode();
	}

	/**
	 * Returns true if this is equal to the given object.
	 * @param object the object to compare.
	 * @return true if this is equal to the given object.
	 */
	@Override
	public boolean equals(Object object) {
		if (object == this) {
			return true;
		}
		if (object instanceof CoordinateRange) {
			CoordinateRange compare = (CoordinateRange) object;
			EqualsBuilder equals = new EqualsBuilder();
			equals.append(this.startLocationId, compare.startLocationId);
			equals.append(this.finishLocationId, compare.finishLocationId);
			return equals.isEquals();
		}
		return false;
	}

	/**
	 * Compare this to the given object.
	 * @param compare the object to compare to.
	 * @return the result of the comparison.
	 */
	@Override
	public int compareTo(ICoordinateRange compare) {
		CompareToBuilder builder = new CompareToBuilder();
		builder.append(this.startLocationId, compare.getStartLocationId());
		builder.append(this.finishLocationId, compare.getFinishLocationId());
		return builder.toComparison();
	}

	/**
	 * Returns this as a string.
	 * @return this as a string.
	 */
	@Override
	public String toString() {
		ToStringBuilder string = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
		string.append("startLocationId", startLocationId);
		string.append("finishLocationId", finishLocationId);
		return string.toString();
	}
}
